package com.aube.base.model;

import com.huyn.baseframework.model.PicItem;
import com.huyn.baseframework.utils.StringUtils;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;

/**
 * Created by huyaonan on 15/11/7.
 */
public class TimeLineItemDetail implements Serializable {

    /**
     * type = QA,VS,VOTE
     */
    public String answer="";
    public int revealTheAnswer=0;
    public List<PicItem> picList;
    public List<OptionItem> optionList;

    /**竞猜的结果信息*/
    public QuizResult timelineQuizInfoRespVo;

    /**信息碎片的位置和缩略图*/
    public PicItem fragmentPicUrl;
    public List<Coordinate> fragmentPointList;
    public String fragmentClick;

    public boolean showFragmentThumbnail() {
        if(fragmentPicUrl == null || StringUtils.isBlank(fragmentPicUrl.picurl))
            return false;
        return true;
    }

    public boolean hasImgInOption() {
        if(optionList != null) {
            for(OptionItem item : optionList)
                if(item.hasImg())
                    return true;
        }
        return false;
    }

    public String getOptionImgUrl(int index) {
        return optionList.get(index).getImgUrl();
    }

    public String getFragmentThumbnail() {
        if(fragmentPicUrl != null)
            return fragmentPicUrl.picurl;
        return null;
    }

    public Coordinate getThumbnailPosition() {
        if(fragmentPointList != null && fragmentPointList.size() > 0)
            return fragmentPointList.get(0);
        return null;
    }

    public int getRightAnswerIndex() {
        if(optionList == null || optionList.size() == 0)
            return -1;
        int index = 0;
        for(OptionItem item : optionList) {
            if(item.isRightAnswer())
                return index;
            index++;
        }
        return -1;
    }

    public String getImgUrl() {
        return getImgUrl(PicItem.IMG_URL);
    }

    public String getImgTag() {
        return getImgUrl(PicItem.IMG_TAG);
    }

    private String getImgUrl(String type) {
        if(picList==null)
            return "";
        for(PicItem item : picList) {
            if(type.equalsIgnoreCase(item.type))
                return item.picurl;
        }
        return "";
    }

    /**
     * type = PIC
     */
    public PicItem pic;
    public String content="";

    public void addToPicMap(HashMap<Integer, String> maps, int startTime) {
        if(pic != null) {
            //超过10s才提前，不然就算了
            if(startTime > 10) {
                startTime -= 10;
                maps.put(startTime, pic.picurl);
                startTime++;
            } else {
                return;
            }
        }

        if(picList==null)
            return;
        for(PicItem item : picList) {
            maps.put(startTime, item.picurl);
            startTime++;
        }
    }

    //新增卡片注释
    public String cardnote;

    //多镜头的倒计时时间
    public int timedown=0;

    public String getOptionId(int index) {
        if(optionList == null || optionList.size() <= index || index < 0)
            return null;
        return optionList.get(index).optionId;
    }

    public String getOptionValue(int index) {
        if(optionList == null || optionList.size() <= index)
            return "";
        return optionList.get(index).optionValue;
    }

    public int getOptionIndex(String optionId) {
        if(optionList == null || StringUtils.isBlank(optionId))
            return -1;
        int inex = 0;
        for(OptionItem item : optionList) {
            if(optionId.equalsIgnoreCase(item.optionId))
                return inex;
            inex++;
        }
        return -1;
    }

}
